<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 *  Role Model Class  
 *  
 * @package XGO CMS v2.0 
 * @subpackage role  
 * @author Manh Nguyen - 08/08/2012 
 * @link http://sunsoft.vn
 */
class Role_model extends DataMapper {

    var $model = 'role_model';
    var $table = 'role';

    // --------------------------------------------------------------------
    // Construct
    // --------------------------------------------------------------------
    public function __construct() {
        parent::__construct();
    }

    // --------------------------------------------------------------------
    // Relationships
    // --------------------------------------------------------------------
    var $has_one = array();
    var $has_many = array(
        'group' => array(
            'class' => 'group_model',
            'other_field' => 'role'
            ));
    // --------------------------------------------------------------------
    // Validation
    // --------------------------------------------------------------------
    var $validation = array();
    // --------------------------------------------------------------------

    /**
     * Default order in query select 
     */
    var $default_order_by = array('id');

    /**
     * string value of object
     * 
     * @access private
     * @param null
     * @return string 
     */
    function __toString() {
        return empty($this->title) ? '---empty---' : $this->title;
    }

    public function get_list() {
        $this->select('id, title, code');
        $list = $this->get();
        return $list;
    }

    /**
     * Array metadata for generate jquery grid
     * show data
     * 
     * @access public
     * @param null
     * @return array 
     */
    function jqgrid_metadata() {
        return array(
            'names' => array(
                'id',
                $this->localize_label('title'),
                $this->localize_label('code'),
                $this->lang->line('description')
            ),
            'model' => array(
                array('name' => 'id', 'hidden' => TRUE, 'key' => TRUE,
                    'editrules' => array('edithidden' => TRUE)
                ),
                array('name' => 'title', 'width' => '100',
                    'searchoptions' => array(
                        'sopt' => array('cn', 'nc', 'eq', 'bw', 'bn', 'ew', 'en')
                    )
                ),
                array('name' => 'code', 'width' => '100',
                    'searchoptions' => array(
                        'sopt' => array('cn', 'nc', 'eq', 'bw', 'bn', 'ew', 'en')
                    )
                ),
                array('name' => 'description',
                    'searchoptions' => array(
                        'sopt' => array('cn', 'nc', 'eq', 'bw', 'bn', 'ew', 'en')
                    )
                )
            )
        );
    }
    
    function total(){
    	$this->select("count(id) as total");
    	$this->get();
    
    	return array(
    			"title" => $this->lang->line('roles'),
    			"total"	=> $this->total,
    	);
    }

}

/* End of file role.php */
/* Location: ./application/models/role.php */